/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BusinessLogic;

import DTO.Manager;
import DataAccess.DataUtility;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Vector;

/**
 *
 * @author Tran anh
 * @version 1.0
 */
public class AccountManagement {

    /**
     * List manager, get from database
     */
    private Vector<Manager> listManager;

    public AccountManagement(){
        
    }
    /**
     * Load list Manager Account from database
     * @return listManager 
     */
    public Vector<Manager> loadManager() {
        try {
            listManager = new Vector<Manager>();

            ResultSet rs = DataUtility.excuteQuery("Select * from ManagerAccount");
            while (rs.next()) {
                Manager manager = new Manager();
                listManager.add(manager);

                manager.setName(rs.getString("name"));
                manager.setPassWord(rs.getString("passWord"));
                manager.setPower(rs.getInt("power"));
                manager.setUserName(rs.getString("userName"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return listManager;
    }

    /**
     * Generate new ID of Manager and not same other Id has in database
     * @return String new ID
     */
    public String createID(){
        //count in table Booth
        //A0001
        return "";
    }

    /**
     * Get information of object manager put into HashMap.
     * Then call method executeProcedure to insert object into database
     * @param manager is new Object to get information pass into database
     */
    public void insert(Manager manager){
        HashMap fiels = new HashMap();

        fiels.put("userName", manager.getUserName());
        fiels.put("passWord", manager.getPassWord());
        fiels.put("Name", manager.getName());
        fiels.put("power", manager.getPower());
        fiels.put("status", manager.getStatus());
        DataUtility.executeProcedure("insertManagerAccount", fiels);
    }

    /**
     * Get information of object manager put into HashMap.
     * Then call method executeProcedure to update object into database
     * @param manager is new Object to get information pass into database
     */
    public void update(Manager manager){
       HashMap fiels = new HashMap();

        fiels.put("userName", manager.getUserName());
        fiels.put("passWord", manager.getPassWord());
        fiels.put("Name", manager.getName());
        fiels.put("power", manager.getPower());
        fiels.put("status", manager.getStatus());
        DataUtility.executeProcedure("updateManagerAccount", fiels);
    }

    public Manager getByIndex(int index) {
        return listManager.get(index);
    }
}
